package shop.controls;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;

import shop.pojo.Brand;
import shop.pojo.Caterage;
import shop.services.BrandServices;
import shop.services.CaterageService;

/**
 * Servlet implementation class CaterageSel
 */
public class CaterageSel extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CaterageSel() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String strPage = request.getParameter("currPage");
		int page =0;
		if(strPage != null){
			page = Integer.parseInt(strPage);
		}
		//获取当前页分类信息
		List<Caterage> list = new CaterageService().selePageCaterage(page*6);
		request.getSession().setAttribute("list", list);
		//获取总页数
		 /*List<Caterage> list = new CaterageService().seleAllCaterage();
		 request.getSession().setAttribute("list", list);*/
		List<Caterage> list1 = new CaterageService().seleAllCaterage();
		int totalCount = list1.size();  //数据总数据
		int totalPage = totalCount%6==0?totalCount/6:totalCount/6+1;
		request.getSession().setAttribute("page", page);
		request.getSession().setAttribute("zongye", totalPage-1);
		request.getSession().setAttribute("totalCount", totalCount);
		request.getRequestDispatcher("jsp2/categoryList.jsp").forward(request, response);
	}

}
